char commandBuffer[5];          // Reading command to this buffer
const int COMMAND_LENGTH = 5;   // Length of command in bytes
const int DEBUG_LED = 13;       // Output pin of debug LED

boolean flag = true;

void setup() 
{
  Serial.begin(9600);
  pinMode(DEBUG_LED, OUTPUT);
  digitalWrite(DEBUG_LED, LOW);
} 

void loop()
{
  while (Serial.available() < COMMAND_LENGTH)
  {
    
  }

  for(int n = 0; n < COMMAND_LENGTH; n++)
  {
    commandBuffer[n] = (byte)Serial.read();
  }

  toggleDebugLed();
  
  for(int n = 0; n < COMMAND_LENGTH; n++)
  {
    Serial.print(commandBuffer[n]);
  }
  
  Serial.flush();
}

void toggleDebugLed()
{
  if (true == flag)
  {
    digitalWrite(DEBUG_LED, HIGH);
    flag = false;
  } else
  {
    digitalWrite(DEBUG_LED, LOW);
    flag = true;
  }
}
